import { getTenantId, getTypeCodeList, getDictType } from "@/api/portalTaskUi/taskList";
export default {
  data () {
    return {
      code: [
        11001,
        11002,
        10000,
        11000,
        12000,
        12001,
        12002,
        12100,
        12200,
        13000
      ]
    };
  },
  async created () {
    console.log("xxxx");
    let data = await this.getTenantIdFun(); // 获取用户id
    if (this.code.includes(data.code)) {
      return;
    }
    this.$store.commit("setUser", data);
    let typeCodeData = await this.getTypeCodeListFun(); // 获取租户名称字典
    let getDictTypeData = await this.getDictTypeFun("task_show_type"); // 设置类型字典
    let targetTypeOptions = typeCodeData.map(v => {
      v.value = v.id;
      v.label = v.name;
      return v;
    });
    console.log(targetTypeOptions);
    this.$store.commit("setUser", data);
    this.$store.commit("setTaskShowTypeOption", getDictTypeData);
    this.$store.commit("setTypeOptions", targetTypeOptions);
    this.flag = true;
  },
  methods: {
    // 租户名称字典
    getTypeCodeListFun () {
      return new Promise(resolve => {
        getTypeCodeList().then(res => {
          console.log(res);
          resolve(res.data.data);
        });
      });
    },
    // 获取类型的字典
    getDictTypeFun (params) {
      // 字典名称
      return new Promise(resolve => {
        getDictType(params).then(res => {
          resolve(res.data.data);
        });
      });
    },
    // 获取用户身份
    getTenantIdFun () {
      return new Promise(resolve => {
        getTenantId().then(res => {
          resolve(res.data.data);
        });
      });
    }
  }
};